#!/bin/sh
if [ "$EUID" = "0" ] || [ "$USER" = "root" ]; then
	echo "Uninstalling USBCID Driver..."
else
	echo "You do not have enough permission to uninstall driver."
	echo "Run installer in root permission."
	echo "Uninstallation canceled."
	exit 0
fi

DIR=/lib/modules/`uname -r`/usb
if [ -f $DIR/cidloader.ko ]; then
	rm $DIR/cidloader.ko
fi

if [ -f $DIR/usbcid.ko ]; then
	rm $DIR/usbcid.ko
fi

depmod
if [ $? -ne 0 ]; then
	echo "Error: command 'depmod' failed."
	exit 1
fi

if [ -f /etc/udev/rules.d/usbcid.rules ]; then
	rm /etc/udev/rules.d/usbcid.rules
else
	DEV_NAME=cid
	DEV_NUM=0
	
	while [ $DEV_NUM -lt 16 ]
	do
		FILENAME=/dev/$DEV_NAME$DEV_NUM
		if [ -e $FILENAME ]; then
			rm -f $FILENAME
		fi
		let DEV_NUM=DEV_NUM+1
	done
fi

echo "USBCID Driver removed."
echo "Uninstallation completed!"

